package models

type Shop struct {
	Id      int    `json:"id" gorm:"type:int(10);unique"`
	Name    string `json:"name" gorm:"type:varchar(30);unique"`
	Address string `json:"address" gorm:"type:varchar(60)"`
	Tel     string `json:"tel" gorm:"type:char(11);unique"`
	Cate    string `json:"cate" gorm:"type:varchar(30)"`
}

func Add(shop *Shop) error {
	err = DB.Create(&shop).Error
	if err != nil {
		return err
	} else {
		return nil
	}
}
func VideoPage(page, pageSize int) ([]Shop, int64, error) {
	var shops []Shop
	var total int64
	err := DB.Model(Shop{}).Count(&total).Error
	if err != nil {
		return nil, 0, err
	}
	err = DB.Model(Shop{}).Offset((page - 1) * pageSize).Limit(pageSize).Find(&shops).Error
	if err != nil {
		return nil, 0, err
	}
	return shops, total, nil
}
func Del(id int) error {
	err := DB.Delete(&Shop{Id: id}).Error
	if err != nil {
		return err
	} else {
		return nil
	}
}
